package com.lesama.list;

/*
    List 集合的遍历方式：
        1.迭代器遍历
        2.增强for循环
        3.forEach
        4.普通for循环
        6.ListIterator（List集合特有的迭代器）
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ListDemo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("可不可以");
        list.add("和你在一起");
        list.add("我们之间");
        list.add("有很多回忆");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }
        System.out.println("-------------------------");
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("-------------------------");
        list.forEach(System.out::println);
        System.out.println("-------------------------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("-------------------------");
        ListIterator<String> stringListIterator = list.listIterator();
        while (stringListIterator.hasNext()) {
            String next = stringListIterator.next();
            System.out.println(next);
        }
    }
}
